import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2025-02-12
 * Time: 10:28
 */
class MyQueue {
    private Stack<Integer> stack1 = new Stack<>();//入队尾元素
    private Stack<Integer> stack2 = new Stack<>();//队首元素
    public MyQueue() {

    }

    public void push(int x) {
        stack1.push(x);
    }

    public int pop() {
        // if(stack2.isEmpty()) return -1;
        int peek = peek();//这里是调用peek()方法，已经包含栈1转栈2了，如果都没有就返回-1了
        stack2.pop();
        return peek;
    }

    public int peek() {
        if(!stack2.isEmpty()) return stack2.peek();
        if(stack1.isEmpty()) return -1;
        while(!stack1.isEmpty()){
            stack2.push(stack1.pop());
        }
        return stack2.peek();
    }

    public boolean empty() {
        if(stack1.isEmpty() && stack2.isEmpty()) return true;
        return false;
    }
}

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue obj = new MyQueue();
 * obj.push(x);
 * int param_2 = obj.pop();
 * int param_3 = obj.peek();
 * boolean param_4 = obj.empty();
 */
public class Test1_7 {
}
